package com.xuecheng.teaching.controller;

import com.xuecheng.api.comment.model.dto.CommentDTO;
import com.xuecheng.api.comment.model.dto.CommentReplyDTO;
import com.xuecheng.api.comment.model.qo.CommentModel;
import com.xuecheng.api.comment.model.vo.CommentReplyVO;
import com.xuecheng.api.comment.model.vo.CommentVO;
import com.xuecheng.api.teaching.CompanyApi;
import com.xuecheng.api.teaching.model.dto.CompanyDTO;
import com.xuecheng.api.teaching.model.qo.QueryCompanyModel;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.uaa.LoginUser;
import com.xuecheng.teaching.agent.CommentApiAgent;
import com.xuecheng.teaching.common.util.UAASecurityUtil;
import com.xuecheng.teaching.service.CompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 教育机构 前端控制器
 */
@Slf4j
@RestController
public class CompanyController implements CompanyApi {

    @Autowired
    private CompanyService companyService;

    @Autowired
    private CommentApiAgent commentApiAgent;

    @Override
    @PostMapping("/m/company/list")
    public PageVO<CommentDTO> queryCompanyList(PageRequestParams params,@RequestBody QueryCompanyModel model) {
        return null;
    }

    @GetMapping ( "/l/company/{tenantId}" )
    public CompanyDTO getByTenantId(@PathVariable ( "tenantId" ) Long tenantId) {
        return companyService.getByTenantId(tenantId);
    }

    @PostMapping("/course-comment")
    public CommentDTO createComment(@RequestBody CommentVO vo){

        LoginUser user = UAASecurityUtil.getUser();
        String username = user.getUsername();

        Long companyId = UAASecurityUtil.getCompanyId();

        return companyService.createComment(vo,companyId,username);
    }

    @Override
    @PostMapping("/course-comment/for-course")
    public PageVO<CommentDTO> queryCommentList(PageRequestParams params, @RequestBody CommentModel commentModel) {
        PageVO<CommentDTO> commentDTOS = commentApiAgent.queryCommentList(params, commentModel);
        return commentDTOS;
    }

    @PostMapping ( "/course-comment/list" )
    public PageVO<CommentDTO> queryCourseCommentList(PageRequestParams params, @RequestBody CommentModel commentModel) {
        PageVO<CommentDTO> commentDTOS = commentApiAgent.queryCourseCommentList(params, commentModel);
        return commentDTOS;
    }

    @GetMapping("/m/course-comment/list-all")
    public PageVO<CommentDTO> queryMCourseCommentList(PageRequestParams params) {
        PageVO<CommentDTO> commentDTOS = commentApiAgent.queryMCourseCommentList(params);
        return commentDTOS;
    }



    @GetMapping("/course-comment/course-statistics/{targetId}")
    public CommentVO statisticsComment(@PathVariable Long targetId) {
        CommentVO commentVO = commentApiAgent.statisticsComment(targetId);
        return commentVO;
    }

    @PostMapping("/course-comment-reply")
    public CommentReplyDTO replyMsg(@RequestBody CommentReplyVO commentReplyVO) {
        CommentReplyDTO commentReplyDTO = commentApiAgent.replyMsg(commentReplyVO);
        return commentReplyDTO;
    }

    @DeleteMapping("/m/course-comment/{commentId}")
    public void deleteComment(@PathVariable Long commentId) {
        commentApiAgent.deleteComment(commentId);
    }

    @DeleteMapping("/m/course-comment/batch-del/{request}")
    public void deleteComments(@PathVariable String request) {
        commentApiAgent.deleteComments(request);
    }


}
